{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), array([b'20140805', b'20140808', b'20140811', b'20140814', b'20140817',\n",
      "       b'20140820', b'20140823', b'20140826', b'20140829', b'20140830'],\n",
      "      dtype=object), array([20385, 20391, 20397, 20403, 20409, 20415, 20421, 20427, 20433,\n",
      "       20435]), array([20383, 20389, 20395, 20401, 20407, 20413, 20419, 20425, 20431,\n",
      "       20433]), array([2, 2, 2, 2, 2, 2, 2, 2, 2, 2]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([2, 2, 2, 2, 2, 2, 2, 2, 2, 2]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])]\n"
     ]
    }
   ],
   "source": [
    "import tensorflow\n",
    "tf = tensorflow.compat.v1\n",
    "# 关闭动态图执行\n",
    "tf.disable_eager_execution()\n",
    "\n",
    "import os\n",
    "\n",
    "tf.Tensor.get_shape()\n",
    "# 找到文件，放入列表\n",
    "file_name = os.listdir('./data/')\n",
    "file_list = [os.path.join('./data/',file) for file in file_name]\n",
    "\n",
    "# 构造文件队列\n",
    "file_queue = tf.train.string_input_producer(file_list)\n",
    "\n",
    "# 实例化阅读器\n",
    "reader = tf.TextLineReader(skip_header_lines=1)\n",
    "# 读取\n",
    "key,value = reader.read(file_queue)\n",
    "\n",
    "# 对内容解码\n",
    "record = [[0],['none'],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0]]\n",
    "example = tf.decode_csv(value,record_defaults=record)\n",
    "\n",
    "example_batch = tf.train.batch(tensors=example,batch_size=10,num_threads=1,capacity=10)\n",
    "\n",
    "with tf.Session() as sess:\n",
    "    # 开启读取文件的线程\n",
    "    coord = tf.train.Coordinator()\n",
    "    threads = tf.train.start_queue_runners(sess,coord=coord)\n",
    "    # 打印读取的内容\n",
    "    print(sess.run(example_batch))\n",
    "    # 回收子线程\n",
    "    coord.request_stop()\n",
    "    coord.join(threads=threads)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}